<?php

namespace Home\Model;

use Think\Model;

class RoleModel extends Model
{
    protected $trueTableName = "think_role";

    protected $_validate = array(
        array('name', 'require', '请填写角色名称！'),
        array('name', '', '该角色已经存在！', 1, 'unique', 1),
        array('pid', 'require', '请选择父级！'),
        array('remark', 'require', '请填写备注！'),
        array('status', 'require', '请填写状态！'),
    );

    public function role_user_add($role_id, $user_id)
    {
        return $this->execute("insert into think_role_user (role_id,user_id) values($role_id,$user_id)");
    }

    public function role_user_update($role_id, $id)
    {
        return $this->execute("update think_role_user set role_id = $role_id   where user_id = $id ");
    }

    public function getAll(){
       return $this->select();
    }

    public function getAllByLimit($opt, $page, $pageSize)
    {
        $data = $this->where($opt)->page($page, $pageSize)->select();
        $count = $this->where($opt)->count();
        return array('data' => $data, 'count' => $count);

    }

}